package com.dlc.shop.systemtest.data.amount;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import com.dlc.shop.bean.model.Product;
import com.dlc.shop.coupon.common.model.Coupon;
import com.dlc.shop.coupon.common.model.CouponProd;
import com.dlc.shop.systemtest.api.amount.ProductApi;
import lombok.AllArgsConstructor;
import lombok.Data;


import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author lanhai
 */
public class CouponData {

    public static Coupon getCoupon(Double condition,Double discount, Double reduceAmount, Integer couponType,Integer stocks,Integer suitableProdType,List<CouponProd> couponProds){
        Coupon coupon = new Coupon();
        coupon.setAfterReceiveDays(0);
        coupon.setCashCondition(condition);
        coupon.setCouponDiscount(discount);
        coupon.setCouponType(couponType);
        coupon.setEndTime(DateUtil.parse("2024-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        coupon.setLaunchTime(null);
        coupon.setLimitNum(1);
        coupon.setPutonStatus(1);
        coupon.setReduceAmount(reduceAmount);
        coupon.setStartTime(DateUtil.parse("2021-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        coupon.setStocks(stocks);
        coupon.setSuitableProdType(suitableProdType);
        coupon.setValidDays(100);
        coupon.setValidTimeType(1);
        coupon.setCouponName("优惠券测试");
        coupon.setCouponProds(couponProds);
        coupon.setSubTitle("");
        return coupon;
    }

    public static Coupon getCouponData(Double condition,Double discount,Double reduceAmount,Integer couponType,Integer stocks,Integer suitableProdType,List<CouponData.CouponProdDto> couponProds){
        Coupon coupon = new Coupon();
        coupon.setAfterReceiveDays(0);
        coupon.setCashCondition(condition);
        coupon.setCouponDiscount(discount);
        coupon.setCouponType(couponType);
        coupon.setEndTime(DateUtil.parse("2024-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        coupon.setLaunchTime(null);
        coupon.setLimitNum(1);
        coupon.setPutonStatus(1);
        coupon.setReduceAmount(reduceAmount);
        coupon.setStartTime(DateUtil.parse("2021-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        coupon.setStocks(stocks);
        coupon.setSuitableProdType(suitableProdType);
        coupon.setValidDays(100);
        coupon.setValidTimeType(1);
        coupon.setCouponName("优惠券测试");
        coupon.setCouponProds(getDiscountItems(couponProds));
        coupon.setSubTitle("");
        return coupon;
    }

    public static Coupon getCouponData(Double condition,Double discount,Double reduceAmount,Integer couponType,Integer getWay,Integer limitNum,
                                       Integer putonStatus, Integer stocks,Integer suitableProdType,List<CouponProd> couponProds){
        Coupon coupon = new Coupon();
        coupon.setAfterReceiveDays(0);
        coupon.setCashCondition(condition);
        coupon.setCouponDiscount(discount);
        coupon.setCouponType(couponType);
        coupon.setEndTime(DateUtil.parse("2025-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        coupon.setGetWay(getWay);
        coupon.setLaunchTime(null);
        coupon.setLimitNum(limitNum);
        coupon.setPutonStatus(putonStatus);
        coupon.setReduceAmount(reduceAmount);
        coupon.setStartTime(DateUtil.parse("2021-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        coupon.setStocks(stocks);
        coupon.setSuitableProdType(suitableProdType);
        coupon.setValidDays(100);
        coupon.setValidTimeType(1);
        coupon.setCouponName("优惠券测试");
        coupon.setCouponProds(couponProds);
        coupon.setSubTitle("");
        return coupon;
    }

    public static List<CouponProd> getCouponProd(List<Long> prodIds){
        List<Product> products = prodIds.stream().map(id -> ProductApi.getProductInfo(id)).toList();
        List<CouponProd> couponProds = new ArrayList<>();
        for (Product product : products) {
            CouponProd couponProd = new CouponProd();
            couponProd.setProdId(product.getProdId());
            couponProd.setProdName(product.getProdName());
            couponProds.add(couponProd);
        }
        return couponProds;
    }

    public static List<CouponProd> getDiscountItems(List<CouponProdDto> couponItemDtos){
        List<CouponProd> couponProdList = new ArrayList<>();
        for (CouponProdDto couponProdDto : couponItemDtos) {
            couponProdList.add(BeanUtil.copyProperties(couponProdDto, CouponProd.class));
        }
        return couponProdList;
    }

    @Data
    @AllArgsConstructor
    public static class CouponProdDto{
        Long prodId;
    }


}
